<template>
  <slot v-if="show"/>
  <div class="authTips" v-if="!show && tips">{{tips}}</div>
</template>
<script setup>
import { ref, onMounted, nextTick } from 'vue'
import { ElMessageBox } from 'element-plus'
import { useUserStore } from '@/pinia/modules/user'
import { emitter } from '@/utils/bus.js'
import { checkStrToArr } from '@/utils/stringFun.js'
const userStore = useUserStore()
// code对应权限树接口中的编码（permission），（每个菜单或者操作按钮都对应的编码）
// tips提示信息
// popup弹窗提示tips
const props = defineProps({
  code: {
    type: String,
    default: ''
  },
  tips: '',
  popup: ''
})
const show = ref(false)
const plists = userStore.userInfo.permissionArr // 权限数组

show.value = checkStrToArr(props.code, plists)

const init = async() => {
  await nextTick()
  if (!show.value) {
    ElMessageBox.confirm(props.tips, '提示',
      {
        confirmButtonText: '确定',
        showCancelButton: false,
        type: 'warning',
      }
    ).then(async() => {
      emitter.emit('closeThisPage') // 关闭当前页面
    }).catch(() => {

    })
  }
}
defineExpose({ init })

</script>
<style lang="scss">
    .authtagstyle{
        display: inline;
    }
    .authTips{
        display: flex;
        justify-content: center;
        padding: 20px 0;
        color: #999;
    }
</style>
